#ifndef SPHENGINE_H
#define SPHENGINE_H

#include <QList>
#include <QObject>
#include <QVector3D>

class Particle;

class SPHEngine : public QObject
{
	Q_OBJECT

	QList<Particle*>& particles;

    QList<Particle>*** grad;
	int qx;
	int qy;
	int qz;

    qreal dt;
    qreal h ;
    qreal k ;
    qreal p0;
    qreal mu;
    qreal sigma;

    QVector3D* m_boxm;
    QVector3D* m_boxM;

public:
    SPHEngine(QList<Particle*>&, QVector3D* boxm, QVector3D* boxM , qreal _h = 0.1, qreal _dt = 0.0001);
	void update();
    void updateMemory();
    void begin();

private:
    int        iX                     (qreal x);
    int        iY                     (qreal y);
    int        iZ                     (qreal z);
    void       memoryInicialization   ();
	void       accelerationCalc       ();
	void       temporalIntegration    ();
    void       temporalIntegrationFirstStep();
    qreal      Wpoli                  (const QVector3D& r);
    qreal      Wspiky                 (const QVector3D& r);
    QVector3D  gradWpoli              (const QVector3D& r);
    qreal      testWpoli              (const QVector3D& r);
    qreal      Wvisc                  (const QVector3D& r);
    qreal      testWSpiky             (const QVector3D& r);
    qreal      laplaWpoli             (const QVector3D& r);
    QVector3D  gradWspiky             (const QVector3D& r);
    qreal      laplaWvisc             (const QVector3D& r);
	void       densityAndPressureCalc ();
	void       forcesCalc             ();
    bool       changePosition         (int i, int ix, int iy, int iz);
    void       colisionDetection      (int i);
};

#endif // SPHENGINE_H
